/**
 * 
 */
package com.telenav.techtalk;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

/**
 * @author yxyao
 *
 */
public class ClipActivity extends Activity {
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new ClipView(this),new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    }
    
    class ClipView extends View{
        private Bitmap bg;
        /**
         * 
         */
        public ClipView(Context context) {
            super(context);
            bg = BitmapFactory.decodeResource(getResources(), R.drawable.hawks_bay);
        }
        
        protected void onDraw(Canvas canvas) {
            int h = bg.getHeight();
            canvas.save(Canvas.CLIP_SAVE_FLAG);
            Path p = new Path();
            RectF rf = new RectF(0,0,bg.getWidth(),bg.getHeight());
            p.addRoundRect(rf, 12, 12, Direction.CW);
            canvas.clipPath(p);
            canvas.drawBitmap(bg, 0, 0, null);
            canvas.restore();
            canvas.save(Canvas.CLIP_SAVE_FLAG);
            p.reset();
            p.addCircle(bg.getWidth()/2, h+10 + h/2, bg.getWidth()/2, Direction.CW);
            canvas.clipPath(p);
            canvas.drawBitmap(bg, 0, h+10, null);
            canvas.restore();
        }
    }

}
